﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

public class Token
{
    private readonly string str;
    private int index;
    private readonly List<string> option = new List<string> 
    {
        "(",
        ")",
        "+",
        "-",
        "*",
        "/",
        "cos",
        "sin",
        "tan",
        "abs",
        "ln",
        "log",
        "exp",
        "!",
        "=",
        "'",
        "\""
    };


    public Token(string str)
    {
        this.str = str.ToLower();
    }

    [DebuggerStepThrough]
    public string Peek()
    {
        foreach (string item in option.Where(item => index < str.Length && str.Substring(index).StartsWith(item)))
            return item;

        if (index < str.Length && Char.IsNumber(str[index]))
            return str[index].ToString();

        if (index < str.Length && Char.IsLetter(str[index]))
            return str[index].ToString();

        return string.Empty;
    }

    [DebuggerStepThrough]
    public string NextToken()
    {
        string item = this.Peek();
        index += item.Length;
        return item;
    }

    public bool IsNumber { get { return Char.IsDigit(this.Peek()[0]); } }
    public bool IsLetters { get { return Char.IsLetter(this.Peek()[0]); } }

    [DebuggerStepThrough]
    public double GetNumber()
    {
        string num = str.Substring(index).Match(@"[+-///*/(]{0,1}\d+[0-9,]*");
        index += num.Length;
        double result = double.Parse(num);
        return result;
    }

    [DebuggerStepThrough]
    public override string ToString()
    {
        return str;
    }

    [DebuggerStepThrough]
    public string GetParsedPart()
    {
        return str.Left(index);
    }
}